Open
Conversation
While injecting props to the wrapped component, prioritize props that come from the HOC state over props that are passed from the parent.
Contributor
|
Thanks for this. While it does make sense, I'm afraid of this potentially breaking existing apps. What do you think about having this as a configured option? |
Author
|
Thank you for taking the time! The challenge is, what can we name that option? :)
|
Contributor
|
This is something that I definitely want and I expected it to behave like this from default, similar to how recompose' hocs are working, e.g. I'm for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While injecting props to the wrapped component, prioritize props that
come from the HOC state over props that are passed from the parent.
Not sure if this is a bug, or if my "fix" breaks something else, but here is the reason I needed this:
I'm doing server-side rendering; and in addition to decorating my components with React Refetch's
connectfor my client-side fetching needs; I also developed another HOC with a nearly same API calledwithInitialRequestthat is able to do fetching on the server side as well:What I need is the ability to override the content of that
brandsFetchcreated bywithInitialRequestusing a lazy refresh method defined inconnect:But this doesn't work, because the HOC returned from
connectfavors parent props over the props it generates from its state in case of a name collision while rendering the child component. SoSomeComponentabove can never get a "refreshed"brandsFetch, as it is stuck with thebrandsFetchcoming from the upper HOC.The obvious workaround is this:
But this is boilerplate I'd rather not duplicate everywhere.
I think it generally makes sense that the props generated by the HOC itself should override the props coming from the parent and not the other way around. I feel that the inner wrapper should have priority in case of name collisions.
Looking forward to your thoughts.
Great library, btw.
: )